fix: paginated calls of thousands of charges took to long#72
Conversation
There was a problem hiding this comment.
Code Review
This pull request removes the get_chain_balance call from the create_billing_credit endpoint to prevent timeouts caused by inefficient history scans. While this change avoids the timeout during credit creation, feedback indicates that the underlying performance bottleneck persists in other areas, such as the balance retrieval endpoint and tool call handler. It is recommended to optimize the balance calculation logic, potentially by caching the last processed offset, to address the systemic performance issue.
I am having trouble creating individual review comments. Click here to see my feedback.
src/canton_mcp_server/server.py (1418-1422)
While removing the get_chain_balance call from this endpoint prevents the timeout during credit creation, the underlying performance issue remains. The get_chain_balance function (and the GET /billing/balance/{party_id} endpoint) will still encounter the same ~30s timeout because it performs a full O(N) scan of the provider's update history starting from offset 0. This means clients will still be unable to retrieve their balance. Furthermore, the same bottleneck exists in handle_tool_call_request (line 358), which will cause tool calls to timeout for busy users. A more robust fix would involve optimizing the balance calculation in canton_billing.py, for example by caching the last processed offset or using a more efficient query mechanism.
No description provided.